<?php

use kzo\base\widgets\ui\common\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\models\statics\OperationEvent;
use kzo\base\widgets\ui\common\grid\ActionColumn;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\LessonDailySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model common\models\c2\search\LessonDailySearch */

$this->title = Yii::t('app.c2', 'Lesson Dailies');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="lesson-daily-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,

        'pjax' => true,
        'hover' => true,
        'showPageSummary' => true,
        'panel' => ['type' => GridView::TYPE_SUCCESS, 'heading' => Yii::t('app.c2', 'Items')],
        'toolbar' => [
            [
                'content' =>
                    Html::a('<i class="fas fa-plus"></i>', ['edit'], [
                        'class' => 'btn btn-success',
                        'title' => Yii::t('app.c2', 'Add'),
                        'data-pjax' => '0',
                    ]) . ' ' .
                    // Html::button('<i class="fas fa-minus"></i>', [
                    //     'class' => 'btn btn-danger',
                    //     'title' => Yii::t('app.c2', 'Delete Selected Items'),
                    //     'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                    // ]) . ' ' .
                    Html::a('<i class="fas fa-redo"></i>', Url::current(), [
                        'class' => 'btn btn-outline-secondary',
                        'title' => Yii::t('app.c2', 'Reset Grid')
                    ]),
                'options' => ['class' => 'btn-group mr-2']
            ],
            '{export}',
            '{toggleData}',
        ],
        'exportContainer' => ['class' => 'btn-group mr-2'],
        'exportConfig' => [],
        'columns' => [
            ['class' => 'kartik\grid\CheckboxColumn'],
            ['class' => 'kartik\grid\SerialColumn'],
            [
                'class' => 'kartik\grid\ExpandRowColumn',
                'value' => function ($model, $key, $index, $column) {
                    return GridView::ROW_COLLAPSED;
                },
                'detail' => function ($model, $key, $index, $column) {
                    return Yii::$app->controller->renderPartial('_detail', ['model' => $model]);
                },
            ],
            'id',
            [

                'attribute' => 'lesson_id',
                'value' => function ($model) {
                    // return $model->lesson ? $model->lesson->name : '';
                    return $model->lesson->name;
                }
            ],
            // 'teacher_id',
            [

                'attribute' => 'teacher_id',
                'value' => function ($model) {
                    return $model->teacher->username;
                }
            ],
            [

                'attribute' => 'lesson_at',
                // 'filterType' => \kartik\widgets\DateTimePicker::className(),
                'filter' => \kartik\widgets\DatePicker::widget([
                    'model' => $searchModel,
                    'type' => \kartik\date\DatePicker::TYPE_COMPONENT_APPEND,
                    'attribute' => 'lesson_at',
                    'pluginOptions' => [
                        'todayHighlight' => true,
                        'orientation' => 'top right',
                        'zIndexOffset' => '9999',
                        'format' => 'yyyy-mm-dd',
                        'autoclose' => true,
                        'todayBtn' => true,
                    ]
                ]),
                'value' => function ($model) {
                    return date("Y-m-d", strtotime($model->lesson_at));
                }
            ],
            'lesson_daytime',
            'allow_people',
            'remain_num',
            // 'status',
            // 'created_at',
            // 'updated_at',
            [
                'attribute' => 'status',
                'class' => '\kartik\grid\EditableColumn',
                'editableOptions' => [
                    'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                    'formOptions' => ['action' => Url::toRoute('editColumn')],
                    'data' => \common\models\c2\statics\LessonDailyStatus::getHashMap('id', 'label'),
                    'displayValueConfig' => \common\models\c2\statics\LessonDailyStatus::getHashMap('id', 'label'),
                ],
                'filter' => EntityModelStatus::getHashMap('id', 'label'),
                'value' => function ($model) {
                    return \common\models\c2\statics\LessonDailyStatus::getLabel($model->status);
                }
            ],
            [
                'class' => ActionColumn::className(),
                'width' => '150px',
                'template' => '{update} {applied}',
                'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return Html::a('<span class="fas fa-pencil-alt"></span>', ['edit', 'id' => $model->id], [
                            'title' => Yii::t('app', 'Info'),
                            'data-pjax' => '0',
                        ]);
                    },
                    'applied' => function ($url, $model, $key) {
                        return Html::a(Yii::t('app.c2', 'Applied'), [
                            '/lesson-apply/default/index',
                            'LessonApplySearch[lesson_daily_id]' => $model->id
                        ], [
                            'title' => Yii::t('app.c2', 'Applied'),
                            'data-pjax' => '0',
                        ]);
                    }
                ]
            ],

        ],
    ]); ?>

</div>
